package ysq.xyg.recovery.controller;

import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.recovery.model.po.RecoveryCircleOrder;
import ysq.xyg.recovery.model.vo.RecoveryCircleOrderVo;
import ysq.xyg.recovery.service.RecoveryCircleOrderService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 回收金模块-回收商圈订单controller层
 *
 * @author congcong tao
 * @date 2019-8-1 15:03:02
 */
@RestController
public class RecoveryCircleOrderController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(RecoveryCircleOrderController.class);
    @Resource
    private RecoveryCircleOrderService recoveryCircleOrderService;

    private RecoveryCircleOrder recoveryCircleOrder;

    /**
     * 分页查询
     *
     * @param recoveryCircleOrderVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-8-1 15:03:02
     */
    @BaseLog(module = "回收金模块",className = "回收商圈订单",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryCircleOrder/page",method = RequestMethod.POST)
    public ReturnEntity page(RecoveryCircleOrderVo recoveryCircleOrderVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = recoveryCircleOrderService.pageLeft(recoveryCircleOrderVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-8-1 15:03:02
     */
    @RequestMapping(value = "/recoveryCircleOrder/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/recovery/recoveryCircleOrderUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            recoveryCircleOrder = recoveryCircleOrderService.selectByPrimaryKey(id);
            String image = recoveryCircleOrder.getImage();
            if (StringUtils.isNotEmpty(image)) {
                view.addObject("imageArr", image.split(","));
            }
            view.addObject("recoveryCircleOrder", recoveryCircleOrder);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-8-1 15:03:02
     */
    @BaseLog(module = "回收金模块",className = "回收商圈订单",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryCircleOrder/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return recoveryCircleOrderService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param recoveryCircleOrderVo Vo对象
     * @author congcong tao
     * @date 2019-8-1 15:03:02
     */
    @BaseLog(module = "回收金模块",className = "回收商圈订单",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryCircleOrder/addOrUpdate", method = RequestMethod.POST)
    public ReturnEntity addOrUpdate(HttpServletRequest request, RecoveryCircleOrderVo recoveryCircleOrderVo){
        return recoveryCircleOrderService.addOrUpdate(recoveryCircleOrderVo, acceptCurrentUser(request));
    }

    /**
     * 根据ids设置回收人
     * @param ids ids用逗号区分
     * @param status
     * @param manageContent
     * @author congcong tao
     * @date 2019/8/2 16:11
     */
    @RequestMapping(value = "/recoveryCircleOrder/updateWasteMemberId")
    public ReturnEntity updateWasteMemberId(String ids, String wasteMemberId, String manageContent){
        return recoveryCircleOrderService.updateWasteMemberId(ids, wasteMemberId, manageContent);
    }
}